<el-dialog
        v-model="editDialog.visible"
        title="{lang share_edit}"
        align="center"
        width="450px"
        style="max-width:100%"
        @open="getShareData">
    <el-form  ref="editFormRef" :model="editDialogForm" label-position="top">
        <el-form-item label="{lang share_title}" prop="title">
            <el-input v-model="editDialogForm.title" placeholder="{lang share_title}"></el-input>
        </el-form-item>
        <el-form-item label="{lang share_times}" >
            <el-input-number v-model="editDialogForm.times" style="width:100%"></el-input-number>
            <el-text class="form-item-helper">{lang share_times_tip}</el-text>
        </el-form-item>
        <el-form-item label="{lang share_password}" prop="password">
            <el-input v-model="editDialogForm.password" placeholder="{lang share_password}" style="width:100%"></el-input>
            <el-text class="form-item-helper">{lang share_password_tip}</el-text>
        </el-form-item>
        <el-form-item label="{lang share_endtime}" >
            <el-date-picker
                    v-model="editDialogForm.fendtime"
                    type="date"
                    clearable
                    placeholder="{lang share_endtime}"></el-date-picker>
            <el-text class="form-item-helper">{lang share_endtime_tip}</el-text>
        </el-form-item>
        <el-form-item label="{lang share_perm}" prop="perm">
            <el-checkbox  v-model="editDialogForm.perm" name="perm">
                {lang download}
            </el-checkbox>
        </el-form-item>


    </el-form>
    <template #footer>
        <div class="dialog-footer">
            <el-button @click="editDialog.visible = false">{lang cancel}</el-button>
            <el-button type="primary" :loading="btnloading" @click="ShareEditSubmit">{lang submit}</el-button>
        </div>
    </template>
</el-dialog>
<script>
    let ShareEditDialogMixin = {
        data() {
            return {
                editDialog: {
                    title:'',
                    sid:'',
                    visible: false,
                },
                btnloading:false,
                editDialogForm: {
                    sid:'',
                    title:'',
                    times:0,
                    password:'',
                    fendtime:'',
                    perm:0
                },
                rules: {
                    title: [
                        { required: true, message: '{lang share_title_empty}', trigger: 'blur' }
                    ]
                }
            }
        },
        methods: {
            getShareData() {
                let self = this;
                axios.post(MOD_URL + '&op=ajax&do=getShareData', {
                    sid: self.editDialog.sid
                }).then(function (response) {

                    if (response.data.success) {
                        self.editDialogForm = response.data.data;

                    } else {
                        self.$message(response.data.msg);
                    }
                });
            },
            ShareEditSubmit() {
                let self = this;

                self.$refs.editFormRef.validate(async function(valid){
                    if (valid) {
                        self.btnloading = true;
                        axios.post(MOD_URL + '&op=ajax&do=shareEditSubmit', self.editDialogForm).then(function (response) {
                            if (response.data.success) {
                                let index = self.tableData.findIndex((current) => {
                                    return current.id == response.data.data.id;
                                });
                                if (index > -1) self.tableData[index] = response.data.data;
                                self.editDialog.visible = false;
                            } else {
                                self.$message(response.data.msg);
                            }
                            self.btnloading = false;
                        });
                    }else{
                        self.$message.error('{lang submit_invalid_msg}');
                        return false;
                    }
                });
            }
        }
    }

</script>